<!-- 
 Copyright 2009 University of  Washington
This code is released under the GPL version 3 - with a copy of the license included
@author Maya Hao Li
 -->
<%@page import="seedpod.webapp.Seedpod"%>
<%@page import="seedpod.webapp.view.HtmlUtil"%>
<%@page import="seedpod.webapp.LimsSession"%>
<%@page import="seedpod.exceptions.DataValidationException"%>
<%@page import="java.util.HashMap"%>
<%@page import="seedpod.webapp.view.htmlwidget.Button"%>
<%@page import="seedpod.webapp.view.Page"%>
<%@page import="seedpod.exceptions.SeedpodException"%>
<%@page import="seedpod.webapp.view.InstanceRenderer"%>

<%
	Page spPage = new Page();
	spPage.addJsLibrary("/javascript/lib/scriptaculous/src/effects.js");
	spPage
	.addJsLibrary("/javascript/lib/scriptaculous/src/scriptaculous.js");
	LimsSession spSession = new LimsSession(request);

	@SuppressWarnings("unchecked")
	HashMap<String, DataValidationException> editorErrors = (HashMap<String, DataValidationException>) spSession
	.getAttribute(InstanceRenderer.VALIDATION_ERROR);

	try {
		InstanceRenderer spInstanceViewer = new InstanceRenderer(request);
		spInstanceViewer.setErrors(editorErrors);
		String clsName = spInstanceViewer.getClsName();
		int oid = spInstanceViewer.getOid();

		String actionEditInstanceUrl = (oid == 0) ? Seedpod
		.getAbsoluteUrl("lims/actionNewInstance?clsName="
				+ clsName) : Seedpod
		.getAbsoluteUrl("lims/actionEditInstance?clsName="
				+ clsName + "&oid=" + oid);

		out.println("<form action=\"" + actionEditInstanceUrl
		+ "\" method=\"post\">");
		out.println(spInstanceViewer.renderEditForm());

		// EDIT button
		Button btnEdit = new Button("editButton", "Save Changes");
		btnEdit.setCssClass("button");
		btnEdit.setType(Button.TYPE_SUBMIT);

		// CANCEL button
		Button btnCancel = new Button("cancelButton", "Cancel");
		btnCancel.setCssClass("button");
		btnCancel.setRedirect("../lims/instance.jsp?clsName=" + clsName
		+ "&oid=" + oid + "&action=view");

		out.println(btnEdit.render());
		out.println(btnCancel.render());

		out.println("</form>");

	} catch (SeedpodException se) {
		out
		.println(HtmlUtil
				.errorMsg("I can't find the object you are trying to edit. Do a search?"));
	}

	spSession.clearAttribute(InstanceRenderer.VALIDATION_ERROR);
%>

